package com.sc.dao.impl;

import com.sc.dao.CategoryDao;
import com.sc.entity.Category;
import com.sc.utils.JDBCUtils;

import java.util.List;

public class CategoryDaoImpl implements CategoryDao {

    @Override
    public int add(Category category) throws Exception {
     String sql=   "insert into category(id,name,parent_id)values(?,?,?)";
     return JDBCUtils.update(sql,new Object[]{category.getId(),category.getName(),category.getParentId()});
    }

    @Override
    public int delete(int id) throws Exception {
        String sql = "delete from category where id = ?";
        return JDBCUtils.update(sql,new Object[]{id});
    }

    @Override
    public int update(Category category) throws Exception {
        String sql = "update category set  name = ?,parent_id =?";
        return JDBCUtils.update(sql,new Object[]{category.getName(),category.getParentId()});
    }

    @Override
    public Category queryById(int id) throws Exception {
        String sql = "select from category where id = ?";
        return JDBCUtils.query(sql,Category.class,new Object[]{id});

    }

    @Override
    public List<Category> queryAll() throws Exception {
        String sql = "select from category ";
        return JDBCUtils.querylist(sql,Category.class,new Object[]{0});


    }
}
